/*******************************************************************************
 * @project: CDMS
 * @package: com.esoon.cdms.action
 * @file: DesignAction.java
 * @author: zhangpei
 * @created: 2017-2-15
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/

/**
 * 
 */
package com.esoon.cdms.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

import com.esoon.cdms.util.CapitalWebServiceUtil;
import com.esoon.cdms.util.JaxbUtil;
import com.mentor.harness.schema.bridgesdesigns.DesignType;
import com.mentor.harness.schema.bridgesdesigns.DesignsType;
import com.mentor.harness.schema.bridgesprojects.ProjectType;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @author Administrator
 * 
 */
public class DesignAction extends ActionSupport implements
		ModelDriven<DesignType> {

	private DesignsType designsType;
	private DesignType design = new DesignType();

	/**
	 * @return the design
	 */
	public DesignType getDesign() {
		return design;
	}

	/**
	 * @param design
	 *            the design to set
	 */
	public void setDesign(DesignType design) {
		this.design = design;
	}

	public static void main(String[] args) throws Exception {
		DesignAction da = new DesignAction();
		// File file =
		// CapitalWebServiceUtil.getAllDesignByProjectName("12Test");
		// System.out.println(file.getAbsolutePath());

	}

	/**
	 * 这个方法后面完善的时候需要传递项目名称String projectName
	 * 
	 * @return
	 * @throws Exception
	 */
	public String getDesignXmlByDesignId() throws Exception {
		// File xmlFile = new File(
		// "E:/workspace_capital/CDMS/temp/Designslist_12Test.xml");
		File xmlFile = CapitalWebServiceUtil.getDesignXmlByDesignId(design
				.getId());
		// File xmlFile = CapitalWebServiceUtil.getAllProjectXml();
		Map session = ActionContext.getContext().getSession();
		session.put("xmlFile", xmlFile.getAbsoluteFile());
		/**
		try {
			InputStream is = new FileInputStream(xmlFile);
			byte[] bytes = new byte[100];
			String xmlStr = "";
			int temp;
			while ((temp = is.read(bytes)) != -1) {
				xmlStr += new String(bytes, 0, temp);
			}
			// System.out.println(xmlStr);

			designsType = (DesignsType) JaxbUtil.xml2Java(DesignsType.class,
					xmlStr);

			// 把项目集合保存到session对象中
			Map session = ActionContext.getContext().getSession();
			for (DesignType design : designsType.getDesign()) {
				System.out.println(design.toString());
			}
			session.remove("designs");
			session.put("designs", designsType.getDesign());

		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		return "designDetail";
	}

	/**
	 * @return the designsType
	 */
	public DesignsType getDesignsType() {
		return designsType;
	}

	/**
	 * @param designsType
	 *            the designsType to set
	 */
	public void setDesignsType(DesignsType designsType) {
		this.designsType = designsType;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
	 */
	@Override
	public DesignType getModel() {
		// TODO Auto-generated method stub
		return this.design;
	}

}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/
